CROSS_COMPILE = arm-none-linux-gnueabihf-

TOPDIR	:= $(shell if [ "$$PWD" != "" ]; then echo $$PWD; else pwd; fi)

HPATH   	= $(TOPDIR)/include

CC = $(CROSS_COMPILE)gcc -D__KERNEL__ -I$(HPATH)
LD = $(CROSS_COMPILE)ld
OBJCOPY = $(CROSS_COMPILE)objcopy

TEXTADDR = 0xC0008000

HEAD = boot/head.o

all: Image

vmlinux: $(HEAD)
	$(LD) -T vmlinux.lds -e stext -Ttext $(TEXTADDR) $(HEAD) -o vmlinux

Image: vmlinux
	$(OBJCOPY) -O binary -R .note -R .comment -S vmlinux $@

$(HEAD): $(HEAD:.o=.S)
	$(CC) -D__ASSEMBLY__ -DTEXTADDR=$(TEXTADDR) -traditional -c $(HEAD:.o=.S) -o $@

run:
	qemu-system-arm -M virt -m 512M -kernel Image -nographic

debug:
	qemu-system-arm -M virt -m 512M -kernel Image -nographic -s -S

gdb:
	gdb-multiarch vmlinux -n -x .gdbinit

clean:
	rm -rf boot/*.o
